@extends('admin.layouts.app')
@section('title', 'admin-bootstrap')
@section("js-head")
    <script></script>
@endsection
@section("content")
    <div class="app-crumb">
        <div class="jing-breadcrumb">
            <i class="jingui-font icon-home"></i>
            <a href="/">首页</a>
            <a><cite>用户管理</cite></a>
        </div>
    </div>
    <div class="app-main">
        <div class="app-result">
            <form name="myform" id="myform" method="post" modelName="design">
                <div class="result-title">
                    <div class="result-list">
                        <a href="{{ url('admin/register') }}"><i class="jingui-font icon-add"></i>用户注册</a>
                        <a id="batchDel" href="javascript:void(0)"><i class="jingui-font icon-del"></i>批量删除</a>
                    </div>
                </div>
                <div class="result-content">
                    <table class="jing-table app-result-table">
                        <colgroup>
                            <col width="15">
                            <col width="110">
                            <col>
                        </colgroup>
                        <thead>
                            <tr>
                                <th>id</th>
                                <th>用户名</th>
                                <th>最后登录时间</th>
                                <th>最后登录IP</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($list as $vo)
                                <tr>
                                    <td>{{$vo->id}}</td>
                                    <td>{{$vo->username}}</td>
                                    <td>{{$vo->logintime}}</td>
                                    <td>{{$vo->loginip}} — {{ $vo->address }}</td>
                                    <td>
                                        <a href="javascript:;" class="js-update-pwd link-update">修改密码</a>
                                        <a class="link-del delete" href="{{ url('admin/user/'. $vo->id) }}">删除</a>
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            </form>
        </div>
        <!--/result-->
    </div>
    <!--/body-->
    <form action="" class="delete-form" method="POST">
        @csrf
        @method('DELETE')
    </form>
@endsection
@section('js')
    <script>
        $(function () {
            Page.init()
        });

        var Page = {
            init: function () {
                this.bind()
            },
            bind: function () {
                var self = this

                $('.js-update-pwd').on('click', function () {
                    self.showUpdatePwdDialog()
                    return false
                })

                $('.delete').on('click', function () {
                    $('.delete-form').attr('action', this.href).submit()
                    return false
                })
            },
            showUpdatePwdDialog () {
                var self = this

                layer.open({
                    title: '修改密码',
                    area: '700px',
                    offset: '200px',
                    type: 1,
                    content: $('#update-pwd'),
                    btn: ['保存', '取消'],
                    // closeBtn: true,
                    yes: function (index, layero) {
                        self.updatePwd()
                        layer.close(index)
                    },
                    btn2: function (index, layero) {
                        //按钮【按钮二】的回调

                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                });
            },
            updatePwd: function () {
                $.ajax({
                    url: "{{ url('admin/user/update') }}",
                    type: 'post',
                    headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
                    data: $('.updatepwd-form').serialize(),
                    success: function (res) {
                        if (res.code === 0) {
                            layer.msg('修改成功', {
                                offset: '15px', icon: 1, time: 1000
                            }, function () {
                                location.href = '{{ route('admin.login.get') }}';
                            })

                        } else {
                            layer.msg(res.msg, {
                                offset: '15px', icon: 2, time: 2000
                            })
                        }
                    },
                    error: function () {

                    }
                })
            }

        }

    </script>
@endsection
@section('inner-body')
    <div id="update-pwd" class="app-update-pwd none">
        <form class="jing-form updatepwd-form" action="">
            <div class="jing-form-item">
                <label class="jing-form-label required">旧密码</label>
                <div class="jing-input-block">
                    <input type="password" name="oldpwd" required lay-verify="oldpwd" autocomplete="off" placeholder="请输入旧密码" class="jing-input">
                </div>
            </div>
            <div class="jing-form-item">
                <label class="jing-form-label required">新密码</label>
                <div class="jing-input-block">
                    <input type="password" name="newpwd" lay-verify="newpwd" autocomplete="off" placeholder="请输入新密码" class="jing-input">
                </div>
            </div>
            <div class="jing-form-item">
                <label class="jing-form-label required">确认新密码</label>
                <div class="jing-input-block">
                    <input type="password" name="renewpwd" lay-verify="renewpwd" autocomplete="off" placeholder="请确认新密码" class="jing-input">
                </div>
            </div>
        </form>
    </div>
@endsection
